<?php
namespace app\decorate\controller;
use app\AdminRest;
use longbingcore\wxcore\WxSetting;
use think\App;
use think\facade\Db;
use think\Request;
use app\decorate\model\AdminDynamic as dyn_model;

class AdminDynamic extends AdminRest{
    protected $model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new dyn_model();
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:动态列表
     */
    public function dynList(){
        $input = $this->_param;
        if(!empty($input['title'])){
            $dis[] = ['a.content','like',"%\\".$input['title']."%"];
        }
        if(!empty($input['progress'])){ //进度
            $dis[] = ['a.progress','=',$input['progress']];
        }
        if(!empty($input['staff_id'])){ //员工
            $dis[] = ['a.staff_id','=',$input['staff_id']];
        }
        if(!empty($input['site_id'])){ //工地
            $dis[] = ['a.site_id','=',$input['site_id']];
        }
        $dis[] = ['a.uniacid','=',$this->_uniacid];
        $data  = $this->model->dynList($dis,$input['limit']);
        return $this->success($data);
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:59
     * @return \think\Response
     * descption:编辑|回显动态
     */
    public function dynUpdate(){

        $input = $this->_input;

        if(count($input)>1){

            $data = $this->model->dynUpdate(['id'=>$input['id']],$input);

        }else{

            $data = $this->model->dynInfo(['a.id'=>$input['id']]);

        }
        return $this->success($data);
    }



    /**
     * @author chenniang
     * @DataTime: 2020-08-18 10:49
     * @功能说明:工地下拉框
     */
    public function siteSelect(){

        $site_model = new \app\decorate\model\AdminSite();

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['status','=',1];

        $site  = $site_model->where($dis)->order('sort desc,create_time desc')->select()->toArray();

        if(!empty($site)){

            foreach ($site as &$v){

                $v['designer_info'] = $site_model->siteStaff($v['designer'],$this->_uniacid);

            }

        }
        return $this->success($site);
    }


    /**
     * User: chenniang
     * Date: 2019-10-23 15:38
     * @return void
     * descption:发动态
     */
    public function dynAdd(){

        $site_model = new \app\decorate\model\AdminSite();

        $input = $this->_input;

        $input['uniacid'] = $this->_uniacid;

        $progerss = $site_model->where(['id'=>$input['site_id']])->value('progress');

        $input['progress'] = $progerss;

        $input['imgs']     = !empty($input['imgs'])?implode(',',$input['imgs']):'';

        $res = $this->model->dynAdd($input);

        return $this->success($res);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-08-18 11:10
     * @功能说明:编辑
     */
    public function dynUpdateV2(){

        $site_model = new \app\decorate\model\AdminSite();

        $input    = $this->_input;

        $progerss = $site_model->where(['id'=>$input['site_id']])->value('progress');

        $input['progress'] = $progerss;

        $input['imgs']     = !empty($input['imgs'])?implode(',',$input['imgs']):'';

        $dis['id'] = $input['id'];

        $res = $this->model->dynUpdate($dis,$input);

        return $this->success($res);


    }



}
